var prefix = "/jzweb/examinationAnswerSheetComyuezi";
// let typesRace = window.location.href.split('?')[1].split('=')[1];
// 				sessionStorage.setItem('types',typesRace);
$(function () {
    load();
    $.ajax({
        url: "/recordPoints/getStuResulteHeader",
        type: "get",
        data: {
            field: "B1"
        },
        success: function (r) {
            if (r.code == 0) {
                $("#numberPeople").text(r.data.numberPepole && '' != r.data.numberPepole ? r.data.numberPepole : '***');
                $("#maxScore").text(r.data.highestScore && '' != r.data.highestScore ? r.data.highestScore : '***');
                $("#minScore").text(r.data.lowestScore && '' != r.data.lowestScore ? r.data.lowestScore : '***');
            } else {
                layer.msg(r.msg);
            }
        }
    });
});

function load() {
    $('#exampleTable')
        .bootstrapTable(
            {
                method: 'get', // 服务器数据的请求方式 get or post
                url: "/recordPoints/getStatisticsByfield", // 服务器数据的加载地址
                //	showRefresh : true,
                //	showToggle : true,
                //	showColumns : true,
                iconSize: 'outline',
                toolbar: '#exampleToolbar',
                theadClasses: "thead-dark",
                striped: true, // 设置为true会有隔行变色效果
                dataType: "json", // 服务器返回的数据类型
                pagination: true, // 设置为true会在底部显示分页条
                singleSelect: false, // 设置为true将禁止多选
                // contentType : "application/x-www-form-urlencoded",
                // //发送到服务器的数据编码类型
                pageSize: 10, // 如果设置了分页，每页数据条数
                pageNumber: 1, // 如果设置了分布，首页页码
                //search : true, // 是否显示搜索框
                showColumns: false, // 是否显示内容下拉框（选择显示的列）
                sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者 "server"
                queryParamsType: "",
                // //设置为limit则会发送符合RESTFull格式的参数
                queryParams: function (params) {
                    return {
                        current: params.pageNumber,
                        size: params.pageSize,
                        field: "B1"
                    };
                },
                responseHandler: function (res) {
                    if (res.code !== '0') {
                        layer.msg(res.msg);
                        return false
                    }
                    let mydata = res.data.records
                    return {
                        "total": res.data.total,//总数
                        "rows": mydata  //数据
                    };
                },
                columns: [
                    {
                        field: 'unitName',
                        title: '参赛单位',
                        formatter: function (value, row, index) {
                            return value
                        }
                    },
                    {
                        field: 'recordNumber',
                        title: '检录序号',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return value
                        }
                    },
                    {
                        field: 'num1',
                        title: '一次加密',
                        formatter: function (value, row, index) {
                            return value
                        }
                    },
                    {
                        field: 'num2',
                        title: '二次加密',
                        formatter: function (value, row, index) {
                            return value
                        }
                    },
                    {
                        field: 'score1',
                        title: '裁判一',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return (value + '').indexOf('-') == 0 ? '-' : value
                        }
                    },
                    {
                        field: 'score2',
                        title: '裁判二',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return (value + '').indexOf('-') == 0 ? '-' : value
                        }
                    },
                    {
                        field: 'score3',
                        title: '裁判三',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return (value + '').indexOf('-') == 0 ? '-' : value
                        }
                    },
                    {
                        field: 'score4',
                        title: '裁判四',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return (value + '').indexOf('-') == 0 ? '-' : value
                        }
                    },
                    {
                        field: 'score5',
                        title: '裁判五',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return (value + '').indexOf('-') == 0 ? '-' : value
                        }
                    },
                    {
                        field: 'remarkA',
                        title: '备注',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return value
                        }
                    },
                    {
                        field: 'finalScore',
                        title: '最终得分',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return value
                        }
                    },
                ],
                // onLoadSuccess: function (data) {
                // 	mergeCells(data,  1, $('#exampleTable'));
                // }
            });

    //$('#exampleTable').bootstrapTable('mergeCells', {index: 1, field: 'unitName', colspan: 2, rowspan: 1});
}

// function mergeCells(data, colspan, target) {
// 	//设置初始行数
// 	var num =0;
//
// 	for (var i = 0; i < data.rows.length; i++) {
// 		//这其实就是bootstrap的mergeCells属性 自带的合并单元格
// 		$(target).bootstrapTable('mergeCells', {index: num, field: 'unitName', colspan: 1, rowspan: 2});
// 		$(target).bootstrapTable('mergeCells', {index: num, field: 'recordNumber', colspan: 1, rowspan: 2});
// 		$(target).bootstrapTable('mergeCells', {index: num, field: 'totalAverageScore', colspan: 1, rowspan: 2});
// 		//我这里是设置每两行合并
// 		num =num+2;
//
// 	}
// }
function reLoad() {
    $('#exampleTable').bootstrapTable('refresh');
}

function add() {
    layer.open({
        type: 2,
        title: '增加',
        maxmin: true,
        shadeClose: false, // 点击遮罩关闭层
        area: ['800px', '520px'],
        content: prefix + '/add' // iframe的url
    });
}

function edit(id) {
    layer.open({
        type: 2,
        title: '编辑',
        maxmin: true,
        shadeClose: false, // 点击遮罩关闭层
        area: ['800px', '520px'],
        content: prefix + '/edit/' + id // iframe的url
    });
}

function remove(id) {
    layer.confirm('确定要删除选中的记录？', {
        btn: ['确定', '取消']
    }, function () {
        $.ajax({
            url: prefix + "/remove",
            type: "post",
            data: {
                'id': id
            },
            success: function (r) {
                if (r.code == 0) {
                    layer.msg(r.msg);
                    reLoad();
                } else {
                    layer.msg(r.msg);
                }
            }
        });
    })
}

function resetPwd(id) {
}

function batchRemove() {
    var rows = $('#exampleTable').bootstrapTable('getSelections'); // 返回所有选择的行，当没有选择的记录时，返回一个空数组
    if (rows.length == 0) {
        layer.msg("请选择要删除的数据");
        return;
    }
    layer.confirm("确认要删除选中的'" + rows.length + "'条数据吗?", {
        btn: ['确定', '取消']
        // 按钮
    }, function () {
        var ids = new Array();
        // 遍历所有选择的行数据，取每条数据对应的ID
        $.each(rows, function (i, row) {
            ids[i] = row['id'];
        });
        $.ajax({
            type: 'POST',
            data: {
                "ids": ids
            },
            url: prefix + '/batchRemove',
            success: function (r) {
                if (r.code == 0) {
                    layer.msg(r.msg);
                    reLoad();
                } else {
                    layer.msg(r.msg);
                }
            }
        });
    }, function () {

    });
}

//导出
function downExcelModelFile() {
    layer.confirm('您确定要导出吗？', {
        btn1: function (index) {
            window.location.href = "/recordPoints/getStatisticsDownload?field=B1";
            layer.close(index)
        }
    });
}

function onchangeExamne(a, b, c, d) {
    let obj = {
        a: a, b: b, c: c, d: d, race: 'A'
    }
    window.sessionStorage.setItem('obj', JSON.stringify(obj));
    layer.open({
        type: 2,
        title: '图片视频信息',
        maxmin: true,
        shadeClose: false, // 点击遮罩关闭层
        area: ['800px', '520px'],
        content: prefix + '/rubrinfo/' // iframe的url
    });
}

function onchangeExamnes(index, id, type) {
    var row = $("#exampleTable").bootstrapTable('getData')[index];
    let obj = {
        id: row.id,
        type: type,
        scoingb1s: row.scoingb1s,
        scoingb2s: row.scoingb2s,
        scoingb3s: row.scoingb3s,
        scoingb4s: row.scoingb4s,
        scoingb5s: row.scoingb5s,
        scoingb1: row.scoingb1,
        scoingb2: row.scoingb2,
        scoingb3: row.scoingb3,
        scoingb4: row.scoingb4,
        scoingb5: row.scoingb5,
    };
    sessionStorage.setItem('obj', JSON.stringify(obj));
    layer.open({
        type: 2,
        title: '修改打分',
        maxmin: true,
        shadeClose: false, // 点击遮罩关闭层
        area: ['800px', '520px'],
        content: prefix + '/exitScore'  // iframe的url
    });
}

// ppt下载
function changeppt(url, id) {
    if (url) {
        var link = document.createElement('a');
        // 设置下载的链接
        link.href = url;
        // 设置下载的文件名
        var filename = url.substring(url.lastIndexOf('/') + 1).split('?')[0];
        link.download = filename
        // 模拟点击下载链接
        link.click();
        return
    }
    layer.msg('暂无ppt')
}